package rpc_client

import (
	"context"

	"github.com/sirupsen/logrus"
	"github.com/smallnest/rpcx/client"
	"go.web.demo.com/api/entity"
	"go.web.demo.com/api/pojo"
)

var userClient client.XClient

//初始化
func createUserClient() {
	logrus.Info("创建UserServiceClient")
	userClient = client.NewXClient("UserService", client.Failtry, client.RandomSelect, discover, client.DefaultOption)
}

// CloseUserClient 关闭客户端
func CloseUserClient() {
	logrus.Info("关闭UserServiceClient")
	e := userClient.Close()
	if e != nil {
		logrus.Error(e)
		panic(e)
	}
	userClient = nil
}

// QueryUser 查询用户
func QueryUser(param *pojo.UserPram) *entity.User {
	user := &entity.User{}
	e := userClient.Call(context.Background(), "QueryUser", param, user)
	if e != nil {
		logrus.Error(e)
		panic(e)
	}
	return user
}
